<?php
class Core_Model_DbTable_Users extends Zend_Db_Table_Abstract {
    protected $_name = 'users';
    
    public function getAll($cols = NULL) {
        $select = $this->select();
        if (isset($cols)) {
            $select->from($this->_name, $cols);
        } else {
            $select->from($this->_name);
        }
        return $this->fetchAll($select);
    }
    
    public function getDetail($uid) {
        $cond = $this->getAdapter()->quoteInto("id = (?)", $uid);
        return $this->fetchRow($cond);
    }
    
    public function batchDelete($ids) {
        $cond = $this->getAdapter()->quoteInto("id IN (?)", $ids);
        $this->delete($cond);
    }
    
    public function getPaginatorAdapter($search_name) {
        $select = $this->select()
                       ->from($this->_name)
                       ->where("username like '%$search_name%'");
        return new Zend_Paginator_Adapter_DbTableSelect($select);
    }
    
    public function login($username, $password) {
        return $this->fetchRow(array(
            $this->getAdapter()->quoteInto("username = (?)", $username),
            $this->getAdapter()->quoteInto("password = (?)", md5($password))
        ));
    }
    
    public function getCustomers() {
        return $this->fetchAll("role = '" . Core_Role::ROLE_PRINCIPAL . "'");
    }
}
?>
